FROM ubuntu:18.04
ENV OH_MY_ZSH_URL 'https://gitee.com/foowaa/oh-my-zsh/raw/master/tools/install.sh'
ENV ZSH_LINUX_URL 'https://gitee.com/foowaa/docker-cmake/raw/master/zsh.sh'
ENV ZSH_SH_PATH 'zsh.sh'
ENV ZSH /root/.oh-my-zsh
ENV IS_DOCKER docker

RUN  sed -i "s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g" /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN rm -Rf /var/lib/apt/lists/*
RUN apt-get update

RUN apt-get install apt-utils build-essential gcc g++ zsh git curl wget dpkg vim silversearcher-ag openssh-server gdb gdbserver rsync -y \
    && chsh -s $(which zsh)
ADD . /code
WORKDIR /code

WORKDIR /
RUN git clone https://gitee.com/foowaa/release.git
WORKDIR /release
RUN tar -xzvf cmake-3.9.5.tar.gz > /dev/null

WORKDIR /release/cmake-3.9.5
RUN ./bootstrap > /dev/null && \
    make -j$(nproc --all) > /dev/null && \
    make install > /dev/null

WORKDIR /

RUN sh -c "$(curl -fsSL ${OH_MY_ZSH_URL})"

RUN curl -fsSL ${ZSH_LINUX_URL} >> ${ZDOTDIR:-$HOME}/${ZSH_SH_PATH}} \
    && bash ${ZDOTDIR:-$HOME}/${ZSH_SH_PATH}} \
    && /bin/zsh -c "source ${ZDOTDIR:-$HOME}/.zshrc"


# Taken from - https://docs.docker.com/engine/examples/running_ssh_service/#environment-variables

RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# 22 for ssh server. 7777 for gdb server.
EXPOSE 22 7777

RUN useradd -ms /bin/bash dev
RUN echo 'dev:dev' | chpasswd

RUN rm -rf /release

CMD ["/usr/sbin/sshd", "-D"]

